package com.xt.purchasingsystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xt.purchasingsystem.dto.SupplierApprovalDto;
import com.xt.purchasingsystem.dto.SupplierRecommendDto;
import com.xt.purchasingsystem.mapper.SupplierRecommendDetailMapper;
import com.xt.purchasingsystem.mapper.SupplierRecommendMapper;
import com.xt.purchasingsystem.model.SupplierRecommend;
import com.xt.purchasingsystem.model.SupplierRecommendDetail;
import com.xt.purchasingsystem.service.SupplierRecommendService;
import com.xt.purchasingsystem.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import com.xt.purchasingsystem.utils.IdWorker;
import com.xt.purchasingsystem.utils.Result;
import com.xt.purchasingsystem.utils.ResultFactory;
import com.xt.purchasingsystem.utils.SerialNumberUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yhp
 * @since 2020-05-31
 */
@Service
@Transactional
public class SupplierRecommendServiceImpl extends ServiceImpl<SupplierRecommendMapper, SupplierRecommend> implements SupplierRecommendService {
    @Autowired
    private SupplierRecommendMapper supplierRecommendMapper;
    @Autowired
    private SupplierRecommendDetailMapper supplierRecommendDetailMapper;
    @Autowired
    private IdWorker idWorker;

    @Override
    public Result saveSupplierRecommend(SupplierRecommendDto supplierRecommendDto) {
        String id = String.valueOf(idWorker.nextId());
        supplierRecommendDto.getSupplierRecommend().setId(id);
        supplierRecommendMapper.insert(supplierRecommendDto.getSupplierRecommend());
        for (SupplierRecommendDetail supplierRecommendDetail : supplierRecommendDto.getSupplierRecommendDetails()) {
            supplierRecommendDetail.setRecommendId(id);
            String did = String.valueOf(idWorker.nextId());
            supplierRecommendDetail.setId(did);
            supplierRecommendDetailMapper.insert(supplierRecommendDetail);
        }
        return ResultFactory.buildSuccessResult("提交成功");
    }

    @Override
    public Result supplierRecommendationReview(Integer currNo, Integer pageSize) {
        PageHelper.startPage(currNo,pageSize);
        List<SupplierRecommendDto> allNoCheckAndNoApply = supplierRecommendMapper.supplierRecommendationReview();
        PageInfo<SupplierRecommendDto> pageInfo = new PageInfo<>(allNoCheckAndNoApply);
        return ResultFactory.buildSuccessResult("查询成功",pageInfo);
    }
}






